#include <iostream>
#include <queue>
#include <vector>

int main()
{
    int N, E;
    std::cin >> N >> E;

    std::vector<int> opened(N, false);
    std::queue<std::pair<int, int>> tm_que;
    std::queue<std::pair<int, int>> open_tm;
    for (int i = 0; i < E; i++)
    {
        int T, P;
        std::cin >> T >> P;
        open_tm.push({T, P});
    }

    tm_que.push(open_tm.front());
    opened[open_tm.front().second] = true;
    open_tm.pop();

    int max_tm = -1;
    std::vector<int> idx_vec;

    while (!tm_que.empty())
    {
        auto open_id = tm_que.front();
        tm_que.pop();

        if (max_tm < open_id.first)
        {
            max_tm = open_id.first;
            idx_vec.clear();
            idx_vec.push_back(open_id.second);
        }
        else if (max_tm == open_id.first)
        {
            idx_vec.push_back(open_id.second);
        }

        while (!open_tm.empty())
        {
            if (open_tm.front().first == open_id.first)
            {
                tm_que.push(open_tm.front());
                opened[open_tm.front().second] = true;
                open_tm.pop();
            }
            else
            {
                break;
            }
        }

        int l_id = (open_id.second - 1 + N) % N;
        if (!opened[l_id])
        {
            tm_que.push({open_id.first + 1, l_id});
            opened[l_id] = true;
        }
        int r_id = (open_id.second + 1) % N;
        if (!opened[r_id])
        {
            tm_que.push({open_id.first + 1, r_id});
            opened[r_id] = true;
        }
    }

    std::cout << idx_vec.size() << std::endl;
    for (int i = 0; i < idx_vec.size() - 1; i++)
    {
        std::cout << idx_vec[i] << " ";
    }
    std::cout << idx_vec.back() << std::endl;

    return 0;
}